package com.qhww.wechatmsg.mp.service;

import com.qhww.wechatmsg.mp.entity.User;
import com.qhww.wechatmsg.mp.mapper.UserMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author guoguo
 * @version 1.0
 * @description: TODO
 * @date 2022/8/31 09:55
 */
@Service
@Transactional
public class UserServiceImpl implements UserService{

    @Resource
    UserMapper userMapper;

    /**
     * 根据手机号查询用户详情
     * @param phone
     * @return
     */
    @Override
    public User selectUser(String phone) {
        return userMapper.queryByPhone(phone);
    }

    /**
     * 根据手机号查询用户详情
     * @param openid
     * @return
     */
    @Override
    public User selectUserByOpenId(String openid) {
        return userMapper.queryByOpenId(openid);
    }

    /**
     * 绑定用户
     * @param user
     * @return
     */
    @Override
    public int insertUser(User user) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        user.setAddTime(formatter.format(calendar.getTime()));
        return userMapper.insert(user);
    }
}
